package com.ykzhujiang.lovespirit.entity;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import java.util.logging.Logger;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Text;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Notice implements Serializable {
	public static final int TYPE_NORMAL = 0;
	public static final int TYPE_DELETED = 1;
	@Persistent
	private String title = "";
	@Persistent
	private String writer = "";
	@Persistent(defaultFetchGroup="true")
	private Text content = new Text("");
	@NotPersistent
	private Calendar calDate = Calendar.getInstance();
	@Persistent
	private Date date = new Date();
	@PrimaryKey
	@Persistent
	private String sourceUrl = "";
	@Persistent
	private String board = "";
	@Persistent
	private String site = "";
	@Persistent(defaultFetchGroup="true")
	private Vector<String> resourceUrl = new Vector<String>();
	@Persistent
	private int hot = 1;
	@Persistent
	private Integer type = TYPE_NORMAL;

	public Notice() {
		// this.calDate.set(1970, 0, 1, 0, 0, 0);
	}

	public String getTitle() {
		// logger.info("1");
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getWriter() {
		// logger.info("2");
		return writer;
	}

	public void setWriter(String writer) {
		this.writer = writer;
	}

	public String getContent() {
		// logger.info("3");
		return content.getValue();
	}

	public void setContent(String content) {
		this.content = new Text(content);
	}

	public String getSourceUrl() {
		// logger.info("4");
		return sourceUrl;
	}

	public void setSourceUrl(String source_url) {
		this.sourceUrl = source_url;
	}

	public String getBoard() {
		// logger.info("5");
		return board;
	}

	public void setBoard(String board) {
		this.board = board;
	}

	public String getSite() {
		// logger.info("6");
		return site;
	}

	public void setSite(String site) {
		this.site = site;
	}

	public Calendar getCalDate() {
		// logger.info("7");
		return calDate;
	}

	public void setCalDate(Calendar date) {
		this.calDate = date;
		this.date = this.calDate.getTime();
	}

	public Date getDate() {
		// logger.info("9");
		// logger.info("getDate1:" + date.toString());
		// date = calDate.getTime();
		// logger.info("getDate2:" + date.toString());
		return date;
	}

	public void setDate(Date date) {
		// logger.info("setDate1:" + date.toString());
		this.date = date;
		// this.calDate.setTime(date);
		// logger.info("setDate2:" + this.calDate.getTime().toString());
	}

	public Vector<String> getResourceUrl() {
		// logger.info("10");
		return resourceUrl;
	}

	public void setResourceUrl(Vector<String> resource_url) {
		this.resourceUrl = resource_url;
	}

	public int getHot() {
		return hot;
	}

	public void setHot(int hot) {
		this.hot = hot;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < resourceUrl.size(); i++) {
			sb.append((String) resourceUrl.get(i));
			sb.append("\r\n");
		}
		return "Notice:\r\n" + "Source_site:" + sourceUrl + "\r\nWriter:"
				+ writer + "\r\nTitle:" + title + "\r\nboard:" + board
				+ "\r\nsite:" + site + "\r\ndate:" + calDate.getTime()
				+ "\r\nContent:\r\n" + content + "\r\nresource_url:\r\n" + sb;

	}

	private static final Logger logger = Logger.getLogger(Notice.class
			.getName());
}